"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _events = _interopRequireDefault(require("events"));

var _logger = _interopRequireDefault(require("./logger.js"));

/*
 * Copyright (C) 2016 Bilibili. All Rights Reserved.
 *
 * @author zheng qian <xqq@xqq.im>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var LoggingControl = /*#__PURE__*/function () {
  function LoggingControl() {
    (0, _classCallCheck2.default)(this, LoggingControl);
  }

  (0, _createClass2.default)(LoggingControl, null, [{
    key: "getConfig",
    value: function getConfig() {
      return {
        globalTag: _logger.default.GLOBAL_TAG,
        forceGlobalTag: _logger.default.FORCE_GLOBAL_TAG,
        enableVerbose: _logger.default.ENABLE_VERBOSE,
        enableDebug: _logger.default.ENABLE_DEBUG,
        enableInfo: _logger.default.ENABLE_INFO,
        enableWarn: _logger.default.ENABLE_WARN,
        enableError: _logger.default.ENABLE_ERROR,
        enableCallback: _logger.default.ENABLE_CALLBACK
      };
    }
  }, {
    key: "applyConfig",
    value: function applyConfig(config) {
      _logger.default.GLOBAL_TAG = config.globalTag;
      _logger.default.FORCE_GLOBAL_TAG = config.forceGlobalTag;
      _logger.default.ENABLE_VERBOSE = config.enableVerbose;
      _logger.default.ENABLE_DEBUG = config.enableDebug;
      _logger.default.ENABLE_INFO = config.enableInfo;
      _logger.default.ENABLE_WARN = config.enableWarn;
      _logger.default.ENABLE_ERROR = config.enableError;
      _logger.default.ENABLE_CALLBACK = config.enableCallback;
    }
  }, {
    key: "_notifyChange",
    value: function _notifyChange() {
      var emitter = LoggingControl.emitter;

      if (emitter.listenerCount('change') > 0) {
        var config = LoggingControl.getConfig();
        emitter.emit('change', config);
      }
    }
  }, {
    key: "registerListener",
    value: function registerListener(listener) {
      LoggingControl.emitter.addListener('change', listener);
    }
  }, {
    key: "removeListener",
    value: function removeListener(listener) {
      LoggingControl.emitter.removeListener('change', listener);
    }
  }, {
    key: "addLogListener",
    value: function addLogListener(listener) {
      _logger.default.emitter.addListener('log', listener);

      if (_logger.default.emitter.listenerCount('log') > 0) {
        _logger.default.ENABLE_CALLBACK = true;

        LoggingControl._notifyChange();
      }
    }
  }, {
    key: "removeLogListener",
    value: function removeLogListener(listener) {
      _logger.default.emitter.removeListener('log', listener);

      if (_logger.default.emitter.listenerCount('log') === 0) {
        _logger.default.ENABLE_CALLBACK = false;

        LoggingControl._notifyChange();
      }
    }
  }, {
    key: "forceGlobalTag",
    get: function get() {
      return _logger.default.FORCE_GLOBAL_TAG;
    },
    set: function set(enable) {
      _logger.default.FORCE_GLOBAL_TAG = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "globalTag",
    get: function get() {
      return _logger.default.GLOBAL_TAG;
    },
    set: function set(tag) {
      _logger.default.GLOBAL_TAG = tag;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableAll",
    get: function get() {
      return _logger.default.ENABLE_VERBOSE && _logger.default.ENABLE_DEBUG && _logger.default.ENABLE_INFO && _logger.default.ENABLE_WARN && _logger.default.ENABLE_ERROR;
    },
    set: function set(enable) {
      _logger.default.ENABLE_VERBOSE = enable;
      _logger.default.ENABLE_DEBUG = enable;
      _logger.default.ENABLE_INFO = enable;
      _logger.default.ENABLE_WARN = enable;
      _logger.default.ENABLE_ERROR = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableDebug",
    get: function get() {
      return _logger.default.ENABLE_DEBUG;
    },
    set: function set(enable) {
      _logger.default.ENABLE_DEBUG = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableVerbose",
    get: function get() {
      return _logger.default.ENABLE_VERBOSE;
    },
    set: function set(enable) {
      _logger.default.ENABLE_VERBOSE = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableInfo",
    get: function get() {
      return _logger.default.ENABLE_INFO;
    },
    set: function set(enable) {
      _logger.default.ENABLE_INFO = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableWarn",
    get: function get() {
      return _logger.default.ENABLE_WARN;
    },
    set: function set(enable) {
      _logger.default.ENABLE_WARN = enable;

      LoggingControl._notifyChange();
    }
  }, {
    key: "enableError",
    get: function get() {
      return _logger.default.ENABLE_ERROR;
    },
    set: function set(enable) {
      _logger.default.ENABLE_ERROR = enable;

      LoggingControl._notifyChange();
    }
  }]);
  return LoggingControl;
}();

LoggingControl.emitter = new _events.default();
var _default = LoggingControl;
exports.default = _default;